package com.onetoall.yjt;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import java.util.Observable;
import java.util.Observer;

/**
 * Created by DELL on 2017/1/23.
 */

public class GuanChaActivity extends Activity  implements Observer{

    private Button btnSet;
    private MyObervese myObervese;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_gucha);
        btnSet = (Button) findViewById(R.id.btn_set);
        myObervese = new MyObervese();
        myObervese.addObserver(this);
    }
    public void click(View view){

//            myObervese.hasChanged();
            myObervese.setChanged();
            myObervese.notifyObservers();
    }

    @Override
    public void update(Observable o, Object arg) {
        Toast.makeText(this,"观察启动",Toast.LENGTH_LONG).show();

    }

    class MyObervese extends Observable{
        @Override
        public synchronized void setChanged() {
            super.setChanged();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        myObervese.deleteObserver(this);
    }
}
